package com.dlyk.manager;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public class RedisManager {

    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    /**
     * 获取redis数据
     * @param key
     * @return
     */
    public Object getValue(String key){
        return redisTemplate.opsForList().range(key, 0, -1);
    }

    /**
     * 保存redis数据
     * @param key
     * @return
     */
    public <T> Object setValue(String key, Collection<T> data){
        Object[] t=new Object[data.size()];
        Object[] array = data.toArray(t);
        return redisTemplate.opsForList().rightPushAll(key,array);
    }
}
